#include "fresnel_effect_ctrl.h"

#include "effects/fresnel_effect.h"
#include "graphics/opengl.h"

namespace venus {
const Effect *FresnelEffectCtrlGlut::effect() const { return effect_; }

FresnelEffectCtrlGlut::~FresnelEffectCtrlGlut() { delete effect_; }

bool FresnelEffectCtrlGlut::OnKeyboard(unsigned char key, int x, int y) {
  if (NULL == effect_) return false;
  switch (key) {
    case '1':
      this->dec_eta_ratio();
      break;
    case '4':
      this->inc_eta_ratio();
      break;
    case '2':
      this->dec_fresnel_bias();
      break;
    case '5':
      this->inc_fresnel_bias();
      break;
    case '3':
      this->dec_fresnel_scale();
      break;
    case '6':
      this->inc_fresnel_scale();
      break;
    case '7':
      this->dec_fresnel_power();
      break;
    case '8':
      this->inc_fresnel_power();
      break;
    default:
      return false;
  }
  return true;
}

bool FresnelEffectCtrlGlut::inc_eta_ratio() {
  float old_val = effect_->eta_ratio();
  float new_val = eta_ratio_.inc(old_val);
  if (old_val == new_val) return false;
  effect_->set_eta_ratio(new_val);
  return true;
}

bool FresnelEffectCtrlGlut::dec_eta_ratio() {
  float old_val = effect_->eta_ratio();
  float new_val = eta_ratio_.dec(old_val);
  if (old_val == new_val) return false;
  effect_->set_eta_ratio(new_val);
  return true;
}

bool FresnelEffectCtrlGlut::inc_fresnel_bias() {
  float old_val = effect_->fresnel_bias();
  float new_val = fresnel_bias_.inc(old_val);
  if (old_val == new_val) return false;
  effect_->set_fresnel_bias(new_val);
  return true;
}

bool FresnelEffectCtrlGlut::dec_fresnel_bias() {
  float old_val = effect_->fresnel_bias();
  float new_val = fresnel_bias_.dec(old_val);
  if (old_val == new_val) return false;
  effect_->set_fresnel_bias(new_val);
  return true;
}

bool FresnelEffectCtrlGlut::inc_fresnel_scale() {
  float old_val = effect_->fresnel_scale();
  float new_val = fresnel_scale_.inc(old_val);
  if (old_val == new_val) return false;
  effect_->set_fresnel_scale(new_val);
  return true;
}

bool FresnelEffectCtrlGlut::dec_fresnel_scale() {
  float old_val = effect_->fresnel_scale();
  float new_val = fresnel_scale_.dec(old_val);
  if (old_val == new_val) return false;
  effect_->set_fresnel_scale(new_val);
  return true;
}

bool FresnelEffectCtrlGlut::inc_fresnel_power() {
  float old_val = effect_->fresnel_power();
  float new_val = fresnel_power_.inc(old_val);
  if (old_val == new_val) return false;
  effect_->set_fresnel_power(new_val);
  return true;
}

bool FresnelEffectCtrlGlut::dec_fresnel_power() {
  float old_val = effect_->fresnel_power();
  float new_val = fresnel_power_.dec(old_val);
  if (old_val == new_val) return false;
  effect_->set_fresnel_power(new_val);
  return true;
}

} // namespace venus
